//
//  MainViewController.m
//  ZCooking
//
//  Created by 韩旭 on 16/8/26.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "MineViewController.h"
#import "MainViewController.h"
#import "FoodViewController.h"
#import "ShopingViewController.h"
#import "FoodClassViewController.h"
#import "CommunityViewController.h"
#import "HMZNavgationController.h"

@interface MainViewController ()

@end

@implementation MainViewController
+ (void)initialize {
    [UINavigationBar appearance];
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}
- (void)viewDidLoad {
    [super viewDidLoad];
//  创建一系列的ViewController
    MineViewController *mine = [[MineViewController alloc] init];
    CommunityViewController *community = [[CommunityViewController alloc] init];
    FoodViewController *food = [[FoodViewController alloc] init];
    ShopingViewController *shop = [[ShopingViewController alloc] init];
    FoodClassViewController *foodClass = [[FoodClassViewController alloc] init];
    [self setUpChildVc:food title:@"食谱" image:@"home_normal" selectImage:@"home_select"];
    [self setUpChildVc:community title:@"社区" image:@"community_normal" selectImage:@"community_select"];
    [self setUpChildVc:shop title:@"商城" image:@"shop_normal" selectImage:@"shop_select"];
    [self setUpChildVc:foodClass title:@"食课" image:@"shike_normal" selectImage:@"shike_select"];
    [self setUpChildVc:mine title:@"我的" image:@"mine_normal" selectImage:@"mine_select"];
}
- (void)setUpChildVc:(UIViewController *)viewCotrolelr title:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage {
    viewCotrolelr.navigationItem.title = title;
    viewCotrolelr.tabBarItem.title = title;
    viewCotrolelr.tabBarItem.image = [UIImage imageNamed:image];
    viewCotrolelr.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
    HMZNavgationController *nav = [[HMZNavgationController alloc] initWithRootViewController:viewCotrolelr];
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
